package com.example.majiang.service;

import com.example.majiang.mapper.UserMappper;
import com.example.majiang.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    UserMappper userMappper;
    public void createOrUpdate(User user){
        User dbUser=userMappper.findByAccountId(user.getAccountId());
        if(dbUser==null){
            user.setGmtCreate(System.currentTimeMillis());
            user.setGmtModified(user.getGmtCreate());
            userMappper.insert(user);
        }
        else{
            dbUser.setToken(user.getToken());
            dbUser.setName(user.getName());
            dbUser.setAvatarUrl(user.getAvatarUrl());
            dbUser.setGmtModified(System.currentTimeMillis());
            userMappper.update(dbUser);
        }


    }
}
